<script setup>
import {ref} from "vue";
//ref('');表示创建一个响应式变量,''是空的占位符,
//如果不写'',ref的初始值是undefined不推荐
const a = ref('');
const b = ref('');
const result = ref('');
const calc = (o)=>{
  result.value = eval(a.value+o+b.value);
}
//eval("5*2")
//结果为10 将字符串形式的算式转为JS进行运算
</script>

<template>
  <h1>计算器练习</h1>
  <input type="text" placeholder="请输入数字1" v-model="a"/>
  <input type="text" placeholder="请输入数字2" v-model="b"/>
  <hr>
  <button @click="calc('+')">加</button>
  <button @click="calc('-')">减</button>
  <button @click="calc('*')">乘</button>
  <button @click="calc('/')">除</button>
  <h4>运算结果:{{result}}</h4>
</template>

<style scoped>

</style>